home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (c) 1991, 1992 Silicon Graphics, Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software and
- * its documentation for any purpose is hereby granted without fee, provided
- * that the name of Silicon Graphics may not be used in any advertising or
- * publicity relating to the software without the specific, prior written
- * permission of Silicon Graphics.
- *
- * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
- *
- * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
- * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
- // -*- C++ -*-
-
- /*
- * Copyright (C) 1990,91 Silicon Graphics, Inc.
- *
- _______________________________________________________________________
- ______________ S I L I C O N G R A P H I C S I N C . ____________
- |
- | $Revision: 1.1007 $
- |
- | Classes : SoSceneViewer
- |
- | Author(s) : Thad Beier, Alain Dumesny, David Mott, Paul Isaacs
- |
- ______________ S I L I C O N G R A P H I C S I N C . ____________
- _______________________________________________________________________
- */
-
- #ifndef _SCENE_VIEWER_
- #define _SCENE_VIEWER_
-
- #include <X11/Intrinsic.h>
- #include <Xm/Xm.h>
- #include <Xm/RowColumn.h>
-
- #include <Inventor/nodes/SoNode.h>
- #include <Inventor/SbPList.h>
- #include <Inventor/nodes/SoPerspectiveCamera.h>
- #include <Inventor/actions/SoGLRenderAction.h> // transparency levels
- #include <Inventor/actions/SoCallbackAction.h>
- #include <Inventor/viewers/SoXtFullViewer.h>
-
- // components
- class SoXtColorEditor;
- class SoXtFileBrowser;
- class SoXtMaterialEditor;
- class SoXtPrintDialog;
- class SoXtTransformSliderSet;
- class SoXtClipboard;
- class SoXtDirectionalLightEditor;
-
- // interaction
- class SoLineHighlight;
- class SoBoxHighlight;
- class SoHighlight;
- class SoSelection;
-
- // nodes
- class SoDataSensor;
- class SoDirectionalLight;
- class SoEnvironment;
- class SoGroup;
- class SoLabel;
- class SoMaterial;
- class SoSceneViewer;
- class SoSwitch;
- class SoLight;
- class SoTransform;
-
- // misc.
- class SvManipList;
-
- enum SvEViewer {
- SV_VWR_EXAMINER = 0,
- SV_VWR_FLY,
- SV_VWR_WALK,
- SV_VWR_PLANE,
- };
-
- enum SvEManipMode {
- SV_NONE, // None
- SV_TRACKBALL, // Trackball manip
- SV_HANDLEBOX, // Handlebox manip
- SV_JACK, // Jack manip
- SV_XFBOX, // TransformBox manip
- SV_DRAGPOINT // DragPoint manip
- };
-
- struct SoSceneViewerData;
- struct SvLightData;
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // Class: SoSceneViewer
- //
- // The SceneViewer component lets you select between different viewers
- // (Examiner, Navigator,..) and lets you perform some simple attribute
- // assignment, and some manipulation of data.
- //
- //////////////////////////////////////////////////////////////////////////////
-
- class SoSceneViewer : public SoXtComponent {
- public:
-
- // Constructor:
- // envFile is the environment file to use. This is where the camera,
- // environment node, and lights are found.
- // Passing NULL means use the default environment.
- //
- // Save will save all the children of root, not including root itself.
- // Save Environment will save the lights and camera environment into envFile
- //
- SoSceneViewer(SoSelection *root, const char *envFile = NULL);
- ~SoSceneViewer();
-
- //
- // Camera operation routines
- //
- void viewAll() { currentViewer->viewAll(); }
- void viewSelection();
- void saveHomePosition() { currentViewer->saveHomePosition(); }
- void setCamera(SoCamera *cam) { currentViewer->setCamera(cam); }
- SoCamera *getCamera() { return camera; }
-
- //
- // Before new data is sent to the viewer, the newData method should
- // be called to disconnect all manipulators and highlights
- //
- void newData();
-
- // Show/hide the pulldown menu bar (default shown)
- void showMenu(SbBool onOrOff);
- SbBool isMenuShown() { return showMenuFlag; }
-
- // Show/hide the viewer component trims (default shown)
- void setDecoration(SbBool onOrOff) { currentViewer->setDecoration(onOrOff); }
- SbBool isDecoration() { return currentViewer->isDecoration(); }
-
- // Show/hide headlight (default on) and get to the headlight node.
- void setHeadlight(SbBool onOrOff) { currentViewer->setHeadlight(onOrOff); }
- SbBool isHeadlight() { return currentViewer->isHeadlight(); }
- SoDirectionalLight *getHeadlight() { return currentViewer->getHeadlight(); }
-
- //
- // Sets/gets the current drawing style in the main view
- // (default VIEW_AS_IS)
- //
- void setDrawStyle(SoXtViewer::DrawStyle style)
- { currentViewer->setDrawStyle(style); }
- SoXtViewer::DrawStyle getDrawStyle()
- { return currentViewer->getDrawStyle(); }
-
- //
- // Sets/gets the current buffering type in the main view
- // (default BUFFER_INTERACTIVE on Indigo, BUFFER_DOUBLE otherwise)
- //
- void setBufferingType(SoXtViewer::BufferType type)
- { currentViewer->setBufferingType(type); }
-
- SoXtViewer::BufferType getBufferingType()
- { return currentViewer->getBufferingType(); }
-
- // Turn viewing on/off (Default to on) in the viewers.
- void setViewing(SbBool onOrOff) { currentViewer->setViewing(onOrOff); }
- SbBool isViewing() { return currentViewer->isViewing(); }
-
- // Set/get the level of transparency type
- void setTransparencyType(SoGLRenderAction::TransparencyType type)
- { currentViewer->setTransparencyType(type); }
- SoGLRenderAction::TransparencyType getTransparencyType()
- { return currentViewer->getTransparencyType(); }
-
- // Grabs render area pixel contents
- unsigned long *copyScreen( short &numRows, short &numColumns )
- { return currentViewer->copyScreen(numRows, numColumns); }
-
- // returns the current render area widget
- Widget getRenderAreaWidget() { return currentViewer->getRenderAreaWidget(); }
-
- #ifdef EXPLORER
- // redraw the scene
- void render() { currentViewer->render(); }
-
- // change the camera
- void changeCamera(SoCamera *newcamera);
-
- // set the EXPLORER user mode callback routine
- void setUserModeEventCallback(SoXtRenderAreaEventCB *fcn);
- #endif /* EXPLORER */
- SbBool readEnvFile(const char *filename);
- SbBool writeEnvFile(const char *filename);
- SbBool BroadcastEnv();
- SbBool ReadBroadcastEnv();
- SoGroup *lightsCameraEnvironment;
-
- protected:
- // redefine these
- virtual const char * getDefaultWidgetName() const;
- virtual const char * getDefaultTitle() const;
- virtual const char * getDefaultIconTitle() const;
-
- private:
- // Scene graph data
- SoSelection *selection; // the same user supplied graph
- SoSeparator *sceneGraph; // user supplied scene graph
-
- // Lights, camera, environment!
- // SoGroup *lightsCameraEnvironment;
- SoLabel *envLabel;
- SoCamera *camera;
- SoEnvironment *environment;
- SoGroup *lightGroup;
-
- void createLightsCameraEnvironment();
-
- // Selection highlight
- SoLineHighlight *lineHighlight;
- SoBoxHighlight *boxHighlight;
-
- //
- // Widgets and menus
- //
-
- Widget mgrWidget; // our topmost form widget
- Widget menuWidget; // topbar menu widget
- SbBool showMenuFlag;
- SoSceneViewerData *menuItems; // list of menu items data
-
- virtual Widget buildWidget(Widget parent, const char *name);
- void buildAndLayoutMenu(Widget parent);
- void buildAndLayoutViewer(SoXtFullViewer *vwr);
-
- // callback for all menu buttons to perform action
- static void processTopbarEvent(Widget, SoSceneViewerData *,
- XmAnyCallbackStruct *);
- // callback when a menu is displayed
- static void menuDisplay(Widget, SoSceneViewerData *, XtPointer);
-
- // this is called after objects are added/deleted or the selection changes
- void updateCommandAvailability();
-
- //
- // File
- //
-
- // file reading methods
- int fileMode;
- char *fileName;
- SbBool useShowcaseBrowser;
- void getFileName();
- void doFileIO(const char *filename);
- SbBool readFile(const char *filename);
- SbBool writeFile(const char *filename);
- // SbBool readEnvFile(const char *filename);
- // SbBool writeEnvFile(const char *filename);
- void deleteScene();
- void save();
- void removeCameras(SoGroup *root);
-
- // motif vars for file reading/writting
- Widget fileDialog;
- static void fileDialogCB(Widget, SoSceneViewer *,
- XmFileSelectionBoxCallbackStruct *);
-
- // showcase file browser vars
- SoXtFileBrowser *browser;
- static void browserCB(void *userData, const char *filename);
-
- // printing vars
- SoXtPrintDialog *printDialog;
- void print();
- static void beforePrintCallback(void *uData, SoXtPrintDialog *);
- static void afterPrintCallback(void *uData, SoXtPrintDialog *);
- SoHighlight *savedHighlight;
- SbBool feedbackShown;
-
- void showAboutDialog();
-
- //
- // Edit
- //
-
- // Select parent, if there is one; select everything.
- void pickParent();
- void pickAll();
-
- // for copy and paste
- SoXtClipboard *clipboard; // copy/paste 3d data
-
- // Paste callback - invoked when paste data transfer is complete
- void pasteDone(SoPathList *pathList);
- static void pasteDoneCB(void *userData, SoPathList *pathList);
-
-
- //
- // Viewing
- //
-
- SoXtFullViewer *viewerList[4]; // list of viewers
- SvEViewer whichViewer; // current viewer ID
- SoXtFullViewer *currentViewer; // current viewer pt
-
- void switchToViewer(SvEViewer newViewer);
-
- // Environment: fog, antialiasing
- SbBool fogFlag; // Fog on/off
- void setFog(SbBool onOrOff); // Turns fog on/off
- SbBool antialiasingFlag; // AA-ing on/off
- void setAntialiasing(SbBool onOrOff); // Turns AA-ing on/off
-
- // Background color
- SoXtColorEditor *backgroundColorEditor;
- const SbColor & getBackgroundColor() { return currentViewer->getBackgroundColor(); }
- void editBackgroundColor(); // Invokes color editor on bkg
- static void backgroundColorCallback(void *userData,
- const SbColor *color);
-
- //
- // Editors
- //
-
- SbBool ignoreCallback;
- SoMaterial *findMaterialForAttach( const SoPath *target );
- SoPath *findTransformForAttach( const SoPath * target );
- // callback used by Accum state action created by findMaterialForAttach
- static SoCallbackAction::Response findMtlPreTailCB(void *data,
- SoCallbackAction *accum,
- const SoNode *);
-
- // transform slider set
- SoXtTransformSliderSet *transformSliderSet;
- void createTransformSliderSet();
-
- // Material editor
- SoXtMaterialEditor *materialEditor;
- void createMaterialEditor();
-
- // Color editor
- SoXtColorEditor *colorEditor;
- void createColorEditor();
-
-
- //
- // Manips
- //
- SvEManipMode curManip;
- SbBool curManipReplaces;
- SvManipList *maniplist; // list of path/manip ptr pairs
-
- // replaces manips with the given type for all selected objects.
- void replaceAllManips( SvEManipMode manipType );
-
- // attaches a manipulator
- void attachManip( SvEManipMode manipType, SoPath *p );
- void attachManipToAll( SvEManipMode manipType );
-
- // detaches a manipulator
- void detachManip( SoPath *p );
- void detachManipFromAll();
-
-
- //
- // Lighting
- //
-
- SbPList lightDataList;
- SoXtDirectionalLightEditor *headlightEditor;
- SvLightData *headlightData;
- void addLight(SoLight *light);
- SvLightData *addLightEntry(SoLight *light, SoSwitch *lightSwitch);
- void addLightMenuEntry(SvLightData *);
- void turnLightOnOff(SvLightData *data, SbBool flag);
- static void lightToggleCB(Widget, SvLightData *, void *);
- void editLight(SvLightData *data, SbBool flag);
- static void editLightToggleCB(Widget, SvLightData *, void *);
- static void editLightColorCB(Widget, SvLightData *, void *);
- void removeLight(SvLightData *);
- static void removeLightCB(Widget, SvLightData *, void *);
- static void lightSubmenuDisplay(Widget, SvLightData *, void *);
-
- // vars to make the light manips all the same size
- SbBox3f lightManipSize;
- SbBool calculatedLightManipSize;
-
- // temporary remove/add the light manip geometry of the attached manips
- // (used for file writting and printing)
- void removeAttachedLightManipGeometry();
- void addAttachedLightManipGeometry();
-
- // Ambient lighting color
- SoXtColorEditor *ambientColorEditor;
- void editAmbientColor(); // Invokes color editor on amb
- static void ambientColorCallback(void *userData,
- const SbColor *color);
-
- //
- // Selection
- //
- // manages changes in the selection.
- static void deselectionCallback(void *userData, SoPath *obj);
- static void selectionCallback(void *userData, SoPath *obj);
-
- // change highlight color with a color editor
- SoXtColorEditor *highlightColorEditor;
- void editHighlightColor();
- static void highlightColorCallback(void *userData,
- const SbColor *color);
-
-
- //
- // Convenience routines
- //
- static SbBool isAffectedByTransform( SoNode *node );
- static SbBool isAffectedByMaterial( SoNode *node );
-
- #ifdef EXPLORER
- //
- // user pick function
- //
- SoXtRenderAreaEventCB *userModeCB;
- void *userModedata;
- SbBool userModeFlag;
- #endif /* EXPLORER */
- };
-
- #endif /* _SCENE_VIEWER_ */
-